
cc.Class({
    extends: cc.Component,

    properties: {
        coinPrefab:{
            default:null,
            type:cc.Prefab
        },
        moneyDisplay:{
            default:null,
            type:cc.Node
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.coinList = []

    },
    emit(){
        for(let i=0;i<15;i++){
                this.coinMove()
        }
        this.node.getChildByName('棒呆了').getComponent(cc.Button).interactable = false
    },
    coinMove(){
        let coin = cc.instantiate(this.coinPrefab)
        this.coinList.push(coin)
        coin.rotation = Math.random()*60-30 +180
        coin.parent = this.node
        coin.x = 0//Math.random()*200-100
        coin.y = -200//Math.random()*200-400
        coin.scale = 1.2
        let worldPos = this.moneyDisplay.parent.convertToWorldSpaceAR(this.moneyDisplay.getPosition())
        let moneyDisplayPos = this.node.convertToNodeSpaceAR(worldPos)
        let desX = moneyDisplayPos.x 
        let desY = moneyDisplayPos.y-100
        let p2x = cc.v2(Math.random()*600-300, Math.random() * (desY - coin.y) + coin.y)
        let p1x = cc.v2(coin.x,coin.y)
        
        var bezier = [ p1x, p2x,cc.v2(desX,desY)];
        var bezierTo = cc.bezierTo(0.6+Math.random()*0.7, bezier).easing(cc.easeCubicActionIn())
        coin.runAction(cc.sequence(bezierTo,cc.callFunc((moneyDisplay)=>{
            //this.runAction(cc.sequence(cc.scaleTo(0.1,1.3,1.3),cc.scaleTo(0.1,1,1)))
            coin.destroy()
        },this.moneyDisplay)))
    }
    // update (dt) {},
});
